package cn.edu.zjx2.controller;

import cn.edu.mp.entity.Grade;
import cn.edu.mp.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/grade")
public class GradeController {
    
    @Autowired
    private GradeService gradeService;
    
    @GetMapping("/page")
    public String page(Model model) {
        model.addAttribute("grades", gradeService.list());
        return "grade/list";
    }
    
    @PostMapping
    @ResponseBody
    public boolean save(@RequestBody Grade grade) {
        return gradeService.save(grade);
    }
    
    @PutMapping
    @ResponseBody
    public boolean update(@RequestBody Grade grade) {
        return gradeService.updateById(grade);
    }
    
    @DeleteMapping("/{id}")
    @ResponseBody
    public boolean delete(@PathVariable Long id) {
        return gradeService.removeById(id);
    }
    
    @GetMapping("/{id}")
    @ResponseBody
    public Grade getById(@PathVariable Long id) {
        return gradeService.getById(id);
    }
} 